R for College Mathematics and Statistics by Pfaff Thomas;
Author:Pfaff, Thomas;
Language: eng
Format: epub
Publisher: CRC Press LLC
9.3 Log Fit
We use rnorm to generate random data for our example of fitting a log function to data. We have not set a seed so results will differ. We let x be the integers from 3 to 100 using the colon command. We then define y to be log(x) (in R log is the natural log function) plus some ânoiseâ added with rnorm. Here our call to rnorm returns a vector of length(x) values from a random normal distribution with mean zero and standard deviation 0.25. Note that y is a vector with the same length as x since the addition of the two vectors,log(x) and rnorm, is element-wise. A simple plot is created with plot (x,y). The Im functions returns the results from fitting the data with the model y = log(x) + b, which is set to the variable Log.fit. The function Log.fit.function is defined using the coefficients returned from coef(Log.fit) and added to the graph with curve. The functions summary(Log.fit), names(Log.fit), and coef(Log.fit) will return information similar to that demonstrated in the Exponential Fit Section.
R Code
> x=3:100
> y=log(x) + rnorm(length(x),0,0.25)
> plot(x,y)
> Log.fit=lm(y~log(x))
> Log.fit.function=function(x)
{coef(Log.fit)[2]*log(x)+coef(Log.fit)[1]}
> curve(Log.fit.function,0,100,lwd=2,add=TRUE)
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Applied | Geometry & Topology |
History | Infinity |
Mathematical Analysis | Matrices |
Number Systems | Popular & Elementary |
Pure Mathematics | Reference |
Research | Study & Teaching |
Transformations | Trigonometry |
Modelling of Convective Heat and Mass Transfer in Rotating Flows by Igor V. Shevchuk(6213)
Weapons of Math Destruction by Cathy O'Neil(5798)
Factfulness: Ten Reasons We're Wrong About the World – and Why Things Are Better Than You Think by Hans Rosling(4465)
Descartes' Error by Antonio Damasio(3147)
A Mind For Numbers: How to Excel at Math and Science (Even If You Flunked Algebra) by Barbara Oakley(3089)
Factfulness_Ten Reasons We're Wrong About the World_and Why Things Are Better Than You Think by Hans Rosling(3032)
TCP IP by Todd Lammle(2993)
Applied Predictive Modeling by Max Kuhn & Kjell Johnson(2884)
Fooled by Randomness: The Hidden Role of Chance in Life and in the Markets by Nassim Nicholas Taleb(2840)
The Tyranny of Metrics by Jerry Z. Muller(2824)
The Book of Numbers by Peter Bentley(2752)
The Great Unknown by Marcus du Sautoy(2521)
Once Upon an Algorithm by Martin Erwig(2464)
Easy Algebra Step-by-Step by Sandra Luna McCune(2441)
Lady Luck by Kristen Ashley(2391)
Practical Guide To Principal Component Methods in R (Multivariate Analysis Book 2) by Alboukadel Kassambara(2365)
Police Exams Prep 2018-2019 by Kaplan Test Prep(2339)
All Things Reconsidered by Bill Thompson III(2247)
Linear Time-Invariant Systems, Behaviors and Modules by Ulrich Oberst & Martin Scheicher & Ingrid Scheicher(2217)
